#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define uint unsigned int
#define endl '\n'

const int INF = 1e9;
const int MOD = 998244353;

#define YES cout << "YES" << '\n'
#define NO cout << "NO" << '\n'

using namespace std;

/*思考

*/
void solve() {
    int n;
    string s;
    cin >> n >> s;
    int cnt = 0;
    for (int i=0;i<n;i++){
        if(s[i]=='0') cnt++;
    }
    int ans = (cnt%2==0) ? 2 : 0;
    cout << ans << '\n';
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 0;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}